function plotlastTS(TS, type)
% plotlastTS(data,labels,dates) Plot the last date in TS structure as a bar chart
%
% Examples:
%     plotlastTS(risk) % risk is a TS structure, plots the last row of data in the TS as a bar chart
%     plotlastTS(risk, 'pie') % plots the last row of data in the TS as a pie chart
%

if nargin < 2, type = 'bar'; end

labels = TS.header;
pdata = TS.data(end,:);

if strcmp(type, 'pie')
  pdata = pdata/sum(pdata);
  pie(pdata, labels);
else
  bar(pdata);
  set(gca, 'XTick', 1:length(labels));
  set(gca, 'XTickLabel',labels);
end

return